const ScenicSpot = require('../../model/scenicSpot/ScenicSpot')

function search(req,res){

  // ScenicSpot.find({
  //   $where: 
  // })
  let arr = []
  let resultArr = []
    ScenicSpot.find({})
      .then((result)=>{

        resultArr = result
        if (resultArr) {
          if (req.query.typename == 'all') {
            arr = result
          }else{
            for (var i=0;i<resultArr.length;i++) {
              if(resultArr[i].typeArr){
                for (var j=0;j<JSON.parse(resultArr[i].typeArr).length;j++){
                  if (JSON.parse(resultArr[i].typeArr)[j] == req.query.typename) {
                    arr.push(result[i])
                  }
                }
              }
              
            }
          }
          res.json({
              code:1,
              msg: '查询成功',
              data: arr
          })
        }else{
              res.json({
                  code:0,
                  msg: '登录失败'
              })
          }
      })
  
}
module.exports = search